local xiaoan = fk.CreateSkill{
  name = "th_xiaoan",
  tags = { Skill.Compulsory }
}

xiaoan:addEffect(fk.TargetConfirming, {
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(xiaoan.name) and target == player and
      data.card and data.card.color ~= Card.Black
      and data.from ~= player then
      local room = player.room
      local mark = player:getMark("th_xiaoan_record-turn")
      local use_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
      if use_event == nil then return false end
      if mark == 0 then
        room.logic:getEventsOfScope(GameEvent.UseCard, 1, function (e)
          local use = e.data
          if use.card and use.card.color ~= Card.Black and
          table.contains(use.tos, player) and data.from ~= player then
            mark = e.id
            room:setPlayerMark(player, "th_xiaoan_record-turn", mark)
            return true
          end
        end, Player.HistoryTurn)
      end
      return mark == use_event.id
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, xiaoan.name)
    data:cancelTarget(player)
  end
})

xiaoan:addTest(function(room, me)
  FkTest.RunAddSkills(me, xiaoan.name)
  local comp2 = room.players[2]
  local slashB = Fk:getCardById(1)
  local slashN = room:printCard("slash")
  local slashR = room:printCard("slash", Card.Heart)

  --- test: comp2对me使用
  --- 期望: me发动技能，此【杀】对me无效
  FkTest.setNextReplies(comp2, {
    --- 黑杀
    FkTest.replyCard(slashB, { me })
  })
  FkTest.runInRoom(function ()
    comp2:gainAnExtraTurn(false, nil, { Player.Play })
  end)
  lu.assertEquals(me.hp, 3)

  FkTest.setNextReplies(comp2, {
    --- 无色杀
    FkTest.replyCard(slashN, { me }),
    --- 红杀
    FkTest.replyCard(slashR, { me })
  })
  FkTest.runInRoom(function ()
    comp2:gainAnExtraTurn(false, nil, { Player.Play })
  end)
  lu.assertEquals(me.hp, 2)
  lu.assertEquals(me:getHandcardNum(), 1)

end)

Fk:loadTranslationTable{
  ["th_xiaoan"] = "宵暗",
  [":th_xiaoan"] = "锁定技，你每回合首次成为其他角色使用非黑色牌的目标时，你摸一张牌并取消你的目标。",
}

return xiaoan
